package io.zhifei.modules.sys.pr.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.zhifei.common.utils.ApiResponse;
import io.zhifei.common.utils.ExcelHead;
import io.zhifei.common.utils.ExecelUitl;
import io.zhifei.modules.sys.pr.entity.Student;
import io.zhifei.modules.sys.pr.entity.XxlJobInfo;
import io.zhifei.modules.sys.pr.mapper.DataCollectionMapper;
import io.zhifei.modules.sys.pr.mapper.JobMapper;
import io.zhifei.modules.sys.pr.model.params.XxlJobInfoParam;
import io.zhifei.modules.sys.pr.service.DataCollectionService;
import io.zhifei.modules.sys.pr.service.JobService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 广告位表 服务实现类
 * </p>
 *
 * @author luoqiming
 * @since 2021-08-09
 */
@Service
public class JobServiceImpl extends ServiceImpl<JobMapper, XxlJobInfo> implements JobService {

    @Override
    public Integer add(XxlJobInfo xxlJobInfo) {
        return this.baseMapper.insert(xxlJobInfo);
    }

    @Override
    @Transactional
    public boolean addSchedu(XxlJobInfoParam xxlJobInfoParam) {
        try {
            xxlJobInfoParam.setGlueType("默认");
            this.saveOrUpdate(xxlJobInfoParam);
            if(null != xxlJobInfoParam.getXxlJobInfoList() && xxlJobInfoParam.getXxlJobInfoList().size() != 0){
                xxlJobInfoParam.getXxlJobInfoList().stream().forEach(xxlJobInfo -> {
                    xxlJobInfo.setChildJobId(String.valueOf(xxlJobInfoParam.getId()));
                });
                this.saveOrUpdateBatch(xxlJobInfoParam.getXxlJobInfoList());
            }

            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public IPage<XxlJobInfoParam> scheduPage(IPage<XxlJobInfo> page, QueryWrapper<XxlJobInfo> qw) {
        return this.baseMapper.scheduPage(page, qw);
    }
}
